package com.ldr.danmuku

import android.widget.TextView
import com.ldr.danmuku.item.DanMuItemViewPool
import com.ldr.danmuku.item.DanMuTextItemView
import java.lang.IllegalArgumentException

/**
 * @author :create by ldr
 * time:2022/12/28 16:49
 * @descript:弹幕库管理类
 */
class DanMuManager {


    companion object{
        val singleton:DanMuManager by lazy(LazyThreadSafetyMode.NONE){
            DanMuManager()
        }
    }

    var mDanMuConfig:DanMuConfig = DanMuConfig()

    var intervalDistance:Float = 0f

    var mDanMuTextItemViewPool:DanMuItemViewPool<DanMuTextItemView> = DanMuItemViewPool()

    /**
     * 获取每帧动画的间隔边距
     */
    fun intervalDistance(parentDistance:Int): Float {
        if (parentDistance <= 0 ) throw IllegalArgumentException("弹幕的布局不能是0")

        val millisecondDistance:Float =  (parentDistance.toFloat() / mDanMuConfig.mDanMUItemSpeed.toFloat()) //每毫秒的距离
        return millisecondDistance * mDanMuConfig.mAnimatorInterval  //每帧动画的距离
    }
    
}